﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Jzy.UI.Web.Areas.Forum.Models;
using Jzy.UI.Web.Areas.Forum.BaseCode;
using Jzy.BLL.Forum;
using Jzy.Model.Forum;
using Jzy.Core.Common;

namespace Jzy.UI.Web.Areas.Forum.Controllers
{
    public class TopicController : Controller
    {
        //
        // GET: /Forum/Topic/

        public ActionResult List(int boardID)
        {
            TopicListModel model = new TopicListModel();
            model.Pager = new PagerSetting();
            model.UrlPrefix = ForumPath.VirtualRoot + "topic/list/" + boardID;
            if (!string.IsNullOrEmpty(Request.QueryString["TypeID"]))
            {
                model.TopicTypeID = int.Parse(Request.QueryString["TypeID"]);

                model.UrlPrefix += "?TypeID=" + model.TopicTypeID;
            }

            ForumTopicBO forum = new ForumTopicBO();
            model.TopList = forum.GetTopList(boardID);
            model.BoardInfo = (new ForumBoardBO()).GetInfo(boardID);
            model.Pager.PageIndex = 1;
            if (!string.IsNullOrEmpty(Request.QueryString["pageno"]))
            {
                model.Pager.PageIndex = int.Parse(Request.QueryString["pageno"]);
            }
            model.Pager.PageSize = 30;
            model.NormalList = forum.GetNormalList(boardID, model.Pager);

            model.Pager.RecordCount = 500;

            return View(ForumPath.Views + "Topic/List.aspx", model);
        }

        public ActionResult Detail(int topicID)
        {
            TopicDetailModel model = new TopicDetailModel();

            ForumTopicBO topic = new ForumTopicBO();
            model.TopicInfo = topic.GetInfo(topicID);
            ForumPostBO post = new ForumPostBO();
            model.Pager = new PagerSetting();
            model.Pager.Where = "TopicID=@p0";
            model.Pager.PageIndex = 1;
            if (!string.IsNullOrEmpty(Request.QueryString["pageno"]))
            {
                model.Pager.PageIndex = int.Parse(Request.QueryString["pageno"]);
            }
            model.Pager.PageSize = 15;
            model.PostList = post.GetList(topicID, model.Pager);

            return View(ForumPath.Views + "Topic/Detail.aspx", model);
        }

    }
}
